//
//  WHSelecetBtn.m
//  WHEasyBizLink
//
//  Created by ShengMeng on 9/20/25.
//

#import "WHSelecetBtn.h"


@implementation WHSelecetBtn

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"SanJiao_g"] forState:UIControlStateNormal];
       
        [self setTitleColor:RGBColor(44, 106, 192) forState:UIControlStateSelected];
        [self setImage:[UIImage imageNamed:@"SanJiao_b"] forState:UIControlStateSelected];
        
        self.titleLabel.font =[UIFont systemFontOfSize:16];
    }
    return self;
}

-(void)setViewTitleBtnWithTitle:(NSString*)title
{
    if(title.length<1) return;
    [self setTitle:title forState:UIControlStateNormal];
    [self sizeToFit];
    [self setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
    
    // 设置最大宽度
    CGFloat maxWidth = ScreenW-40; // 你想要设置的最大宽度
    CGSize titleSize = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName: self.titleLabel.font}];
    CGFloat buttonWidth = MIN(titleSize.width + self.contentEdgeInsets.left + self.contentEdgeInsets.right+20, maxWidth);
     
    // 设置按钮的frame
    self.xh_Width = buttonWidth;
}


@end
